<template>

  <div ref="t9">

    <div class="print-wrap-210 print-wrap-normal" style="width:210mm;border:1px solid #000;padding:10px">
      <div style="text-align:center; ">
        <!-- <div class="logopanel" v-if="s.IsShowLogo">
                <img v-bind:src="s.LogoUrl" v-bind:width="s.LogoWidth" v-bind:height="s.LogoHeight" />
            </div> -->
        <h2 class="hotelname">{{ seller ? seller.sellerName : '酒店' }}退款单</h2>
        <!-- <div class="logogstate">
                <span v-if="s.CurrentPrintTimes"><span class="printtimeslabel">打印次数: </span> {{s.CurrentPrintTimes}}</span>
            </div> -->

      </div>

      <p class="panelone panelone1_2 panelone2">
        <span>姓名:</span>
        <span class="inputspan">{{ info ? info.peopleEntity.name : '貂蝉' }}</span>
        <span>单号:</span>
        <span class="inputspan">{{ rowData ? rowData.ruSysNo : 'R20200101001' }}</span>
      </p>

      <p class="panelone panelone1_2 panelone2">
        <span>房号:</span>
        <span>{{ info ? info.floorRoomEntity.roomSign : '' }}{{ info ? info.floorRoomEntity.roomNum : '6319' }}</span>
        <span>证件:</span>
        <span>{{ info ? peopleEntityType[info.peopleEntity.type] : '411' }}</span>
      </p>

      <p class="panelone panelone1_2 panelone2">
        <span>号码:</span>
        <span>{{ info ? info.peopleEntity.certificatesNumber : '1853838xxxx' }}</span>
        <span>性别:</span>
        <span v-if="info">
          <span v-if="info.peopleEntity.sex == 1">男</span>
          <span v-if="info.peopleEntity.sex == 2">女</span>
        </span>
        <span v-else>女</span>
      </p>
      <p class="panelone panelone1_2 panelone2">
        <span>金额:</span>
        <span v-if="rowData">
          <span v-if="rowData.payPrice">{{rowData.payPrice}}</span>
          <span v-else>198</span>
        </span>
        <span v-else>198</span>
        <span>退款方式:</span>
          <span v-if="rowData">
            {{rowData.nowTypeName?rowData.nowTypeName:'微信'}}
          </span>
        <span v-else>微信</span>
      </p>
      <p class="panelone panelone1_2 panelone2">
        <span>房型:</span>
        <span>{{ info ? info.roomEntity.name : '大床房' }}</span>
        <span>来时:</span>
        <span>{{ info ? info.singleEntity.arrivalsTime : '2019-09-01 12:51' }}</span>
      </p>
      <p class="panelone panelone1_2 panelone2">
        <span>离时:</span>
        <span>{{ info ? info.singleEntity.predissociationTime : '2019-09-02 02:00' }}</span>
        <span>地址:</span>
        <span>{{ info ? info.peopleEntity.address : '无' }}</span>
      </p>
      <p class="panelone panelone1_2 panelone2">
        <span>收银:</span>
        <span>{{ user ? user.username : '易信' }}</span>
        <span>协议:</span>
        <span>无</span>
      </p>

      <table style="width:100%;font-size:13px; " class="mf15mmwithbigsize">
        <tr>
          <td>房号</td>
          <td>房型</td>
          <td>科目</td>
          <td>标价</td>
          <td>折扣价</td>
        </tr>
<!--        <tr>
          <td colspan="4"><hr style="border:1px dashed #000; height:1px" /></td>
        </tr> -->
        <tr>
          <td>{{ info ? info.floorRoomEntity.roomSign : '' }}{{ info ? info.floorRoomEntity.roomNum : '6139' }}</td>
          <td>{{ info ? info.roomEntity.name : '大床房' }}</td>
          <td>
            <span v-if="rowData">
                <span v-if="rowData.payType == 0">预收账款</span>
                <span v-if="rowData.payType == 1">信用卡授权</span>
                <span v-if="rowData.payType == 2">{{ info.peopleEntity.consumeName }}</span>
                <span v-if="rowData.payType == 3">押金</span>
                <span v-if="rowData.payType == 4">房费</span>
                <span v-if="rowData.payType == 5">预收退款</span>
                <span v-if="rowData.payType == 6">结账收款</span>
                <span v-if="rowData.payType == 7">结账退款</span>
                <span v-if="rowData.payType == 8">退押金</span>
              </span>
            <span v-else>房费</span>
          </td>
          <td>{{ rowData ? rowData.payPrice : '198' }}</td>
          <td></td>
        </tr>
<!--        <tr>
          <td colspan="4"><hr style="border:1px dashed #000; height:1px" /></td>
        </tr> -->
      </table>

      <div v-html="note" class="mf15mmwithbigsize"></div>

      <p class="panelone">
        <span>宾客签字:</span>
        <span class="inputspan" style="width: 40mm; flex: 0 0 auto;"></span>
      </p>
      <p class="panelone">
        <span>手工单号:</span>
        <span v-if="rowData">
          <span v-if="rowData.inpOrderNum">{{rowData.inpOrderNum}}</span>
          <span v-else>S202007021210080027</span>
        </span>
        <span v-else>S202007021210080027</span>
      </p>
      <p class="panelone">
        <span>付款时间:</span>
        <span v-if="rowData">
          <span v-if="rowData.creatTime">rowData.creatTime</span>
          <span v-else>2019年8月6日 13:13</span>
        </span>
        <span v-else>2019年8月6日 13:13</span>
      </p>
      <p class="panelone">
        <span>打印时间:</span>
        <span>{{ nowDate + ' ' + nowTime + ' ' }}</span>
      </p>
      <p class="panelone">
        <span>联系电话:</span>
        <span>{{ seller ? seller.tel : '模板' }}</span>
      </p>

      <p class="panelone">
        <span>酒店地址:</span>
        <span>{{ seller ? seller.address : '模板' }}</span>
      </p>
    </div>
  </div>
</template>
<script>
import moment from 'moment';
export default {
  props: ['note', 'info', 'priceMap', 'currData', 'financeData'],
  watch: {
    financeData (newV, oldV) {
      // do something
      this.financeData = newV
      this.$nextTick(() => {
        this.sum();
      })
    },
    deep: true
  },
  data () {
    return {
      financeData: [],
      nowDate: "",    // 当前日期
      nowTime: "",    // 当前时间
      nowWeek: "",     // 当前星期
      today: moment().format('YYYY-MM-DD'),
      user: {},
      seller: {},
      sum1: 0,
      sum2: 0,
      dataList: [],
      ftype: '模板',
      payTypes: ['预收账款', '信用卡授权', '消费', '押金', '房费', '预收退款', '结账收款', '结账退款', '退押金'],
      peopleEntityType: ['居民身份证', '户口簿', '军官证', '警官证', '士兵证', '护照', '其他'],
      rowData: {}
    }
  },
  methods: {
    currentTime () {
      setInterval(this.getDate, 500);
    },
    getUser () {
      this.$http({
        url: this.$http.adornUrl(`/hotel/thotelprinttemplate/printInfo`),
        method: 'get',
      }).then(({ data }) => {
        if (data.code === 0) {
          this.user = data.user;
          this.seller = data.seller;
        }
      })
    },
    sum () {
      // for (index in this.financeData) {
      //   console.log("值：",index)
      //   if (this.financeData[index].payType == 2 || this.financeData[index].payType == 4) {
      //     this.sum1 += item.payPrice;
      //   }
      //   if (this.financeData[index].payType == 0 || this.financeData[index].payType == 3) {
      //     this.sum2 += item.payPrice
      //   }
      // }
      this.sum1 = 0;
      this.sum2 = 0;
      this.financeData.forEach(element => {
        if (this.sum1 == 0) {
          if (element.type == 0) {
            this.ftype = "未结"
          }
          if (element.type == 1) {
            this.ftype = "已结"
          }
          if (element.type == 2) {
            this.ftype = "已转"
          }
        }
        if (element.payType == 2 || element.payType == 4) {
          this.sum1 += element.payPrice;
        }
        if (element.payType == 0 || element.payType == 3) {
          this.sum2 += element.payPrice
        }
      });
    },
    getDate: function () {
      var _this = this;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let week = new Date().getDay();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      if (week == 1) {
        this.nowWeek = "星期一";
      } else if (week == 2) {
        this.nowWeek = "星期二";
      } else if (week == 3) {
        this.nowWeek = "星期三";
      } else if (week == 4) {
        this.nowWeek = "星期四";
      } else if (week == 5) {
        this.nowWeek = "星期五";
      } else if (week == 6) {
        this.nowWeek = "星期六";
      } else {
        this.nowWeek = "星期日";
      }
      _this.nowTime = hh + ":" + mf;
      _this.nowDate = yy + "/" + mm + "/" + dd;
    },
    setRowData (data) {
      this.rowData = data;
    }
  },
  mounted () {
    this.currentTime();
    if (this.info) {
      if(this.currData){
        this.currData = this.priceMap[moment(this.info.peopleEntity.arrivalsTime).format('YYYY-MM-DD')];
      }
    }
    this.getUser();
  },

}
</script>
